#ifndef _MUNIX_SIGNALS_H_
#define	_MUNIX_SIGNALS_H_
/*******************************************************************************
 ** Name: signals.h                                                           **
 ** Description:              **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the license.txt within              **
 ** this distribution or at http://www.munixos.net/licensing.                 **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $HOME/license.txt.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 **                                                                           **
 ** Copyright (c) 2009-2010  Barry Gian James.                                **
 ** All rights reserved.                                                      **
 **                                                                           **
 ** Ref: $HeadURL$
 ******************************************************************************/
// Portions (C) 2011 OpenHouseware, LLC.
// All Rights Reserved
#define _MUNIX_SIGNALS_H_ID "$Id$"
// Last Modified $DateTime$ by $Author$
#include <types.h>

typedef uint32_t	sigset_t;

// POSIX-defined signals (or most/some of them)
// Classic signal names
// Defines for fun. We actually use the enum class, though.
#define SIGUNK		0x00	// bjames signal
#define SIGALARM    0x01    // alarm time outs. alarm()
#define SIGABRT     0x02    // abort proc exec. abort()
#define SIGFPE      0x03    // illegal arithm instruction
#define SIGHUP      0x04    // terminal hangup
#define SIGILL      0x05    // illegal instruction
#define SIGINT      0x06    // process interrupt. Ctrl-C
#define SIGKILL     0x07    // kill a process
#define SIGPIPE     0x08    // illegal write to pipe
#define SIGQUIT     0x09    // proc quit.
#define SIGSEGV     0x0a    // segmentation fault
#define SIGTERM     0x0b    // proc termination
#define SIGUSR1     0x0c    // user defined
#define SIGUSR2     0x0d    // user defined
#define SIGCHLD     0x0e    // notification to parent proc that child has died
#define SIGCONT     0x0f    // resume exec of stopped proc
#define SIGSTOP     0x10    // stop proc exec
#define SIGTTIN     0x11    // stop bkg proc when it reads from ctrl term
#define SIGTSTP     0x12    // stop proc exec with Ctrl-Z
#define SIGTTOU     0x13    // stop bkg proc when it writes to ctrl term

#define SIGIO       0x14    // socket I/O possible
#define SIGPWR      0x15    // power  failure/brownout
#define SIGPOLL     0x16    // polling event signal
#define SIGBUS		0x17	// bus error

extern char const __attribute__((__progmem__))  sigbjames[];
extern char const __attribute__((__progmem__))  sigAlarm[];
extern char const __attribute__((__progmem__))  sigAbort[];
extern char const __attribute__((__progmem__))  sigFPE[];
extern char const __attribute__((__progmem__))  sigHUP[];
extern char const __attribute__((__progmem__))  sigIllegal[];
extern char const __attribute__((__progmem__))  sigInt[];
extern char const __attribute__((__progmem__))  sigKill[];
extern char const __attribute__((__progmem__))  sigPipe[];
extern char const __attribute__((__progmem__))  sigQuit[];
extern char const __attribute__((__progmem__))  sigSEGV[];
extern char const __attribute__((__progmem__))  sigTerm[];
extern char const __attribute__((__progmem__))  sigUsr1[];
extern char const __attribute__((__progmem__))  sigUsr2[];
extern char const __attribute__((__progmem__))  sigChild[];
extern char const __attribute__((__progmem__))  sigCont[];
extern char const __attribute__((__progmem__))  sigStop[];
extern char const __attribute__((__progmem__))  sigTtin[];
extern char const __attribute__((__progmem__))  sigTStop[];
extern char const __attribute__((__progmem__))  sigTtou[];
extern char const __attribute__((__progmem__))  sigIO[];
extern char const __attribute__((__progmem__))  sigPower[];
extern char const __attribute__((__progmem__))  sigPoll[];
extern char const __attribute__((__progmem__))  sigBus[];

extern const char * SignalStrings[];

enum class sig
{
    bjames, alarm, abort, math, hangup, illegal, interrupt, kill,
    pipe, quit, segfault, terminate, user1, user2, child, cont,
    stop, tstoprd, tstop, tstopwr, io, power, poll, bus,

    maxsig
};

// Signal stack
struct SigStack
{
	char *	stackPtr;
	sig		current;
};

// Signal Actions
struct SigAction
{
	void		(*signalHandler)();
	sigset_t	mask;
	uint8_t		flags;
};

// The SigContext structure handles information that is pushed onto the
// stack when a signal is delivered. See Open Solaris signal.h
struct SigContext
{
	sigset_t	origMask;	// signal mask to restore
	uint32_t	stackPtr;
	uint32_t	progCtr;
};

void (*signal())();


#endif	/* _MUNIX_SIGNALS_H_ */

